package reflection;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

/**
 * @ClassName Demo04
 * @Description TODO
 * 获取泛型
 * @Author liang
 * @Date 2018/10/18 10:57
 * @Version 1.0
 **/
public class Demo04 {
    public void test01(Map<String,User> map,List<User> list){
        System.out.println("Demo04.test01() ...");
    }
    public Map<Integer,User> test02(){
        System.out.println("Demo04.test02() ...");
        return null;
     }
    public static void main(String [] args) throws NoSuchMethodException {
        //获取指定方法参数泛型信息
        Method m = Demo04.class.getMethod("test01", Map.class, List.class);
        Type[] t = m.getGenericParameterTypes();
        for(Type paramType:t){
            System.out.println("m :"+paramType);
            if(paramType instanceof ParameterizedType){
                Type[] genericTypes = ((ParameterizedType) paramType).getActualTypeArguments();
                for(Type genericType:genericTypes){
                    System.out.println("泛型类型："+genericType);
                }
            }
        }
    }
}
